<template>
  <div>
    <Card>
      <Row>
        <Form ref="searchForm" inline :label-width="70" class="search-form">
          <FormItem label="文件名">
            <Input
              type="text"
              v-model="searchForm.fileName"
              placeholder="请输入文件名"
              clearable
              style="width: 150px"
            />
          </FormItem>
          <FormItem label="导出类型">
            <Select
              clearable
              v-model="searchForm.fileType"
              style="width: 150px"
            >
              <Option :value="1">用户数据</Option>
              <!-- <Option :value="2">订单数据</Option> -->
              <Option :value="3">运单数据</Option>
              <Option :value="4">监控数据</Option>
              <Option :value="5">发票数据</Option>
              <Option :value="6">财务数据</Option>
              <Option :value="7">统计数据</Option>
            </Select>
          </FormItem>
          <FormItem label="状态">
            <Select clearable v-model="searchForm.state" style="width: 150px">
              <Option :value="1">成功</Option>
              <Option :value="2">失败</Option>
            </Select>
          </FormItem>
          <FormItem label="导出日期">
            <DatePicker
              clearable
              type="daterange"
              placement="bottom-end"
              placeholder="请选择日期"
              style="width: 200px"
              v-model="date"
              @on-change="changeDate"
            ></DatePicker>
          </FormItem>
          <FormItem style="margin-left: -35px" class="br">
            <Button @click="handleSearch" type="primary" icon="ios-search"
              >搜索</Button
            >
            <Button @click="handleReset">重置</Button>
            <Button @click="getDataList" icon="md-refresh">刷新</Button>
            <!-- <Button @click="echartss" icon="md-refresh">echarts</Button> -->
          </FormItem>
        </Form>
      </Row>

      <Row>
        <Table
          :loading="loading"
          border
          :columns="columns"
          :data="data"
          ref="table"
          class="table"
        ></Table>
      </Row>
      <Row type="flex" justify="end" class="page" style="margin-top: 2vh">
        <Page
          :current="searchForm.pageNumber"
          :total="total"
          :page-size="searchForm.pageSize"
          @on-change="changePage"
          @on-page-size-change="changePageSize"
          :page-size-opts="[10, 20, 50]"
          size="small"
          show-total
          show-elevator
          show-sizer
        ></Page>
      </Row>
    </Card>
  </div>
</template>

<script>
// 根据你的实际请求api.js位置路径修改
import { downloadRecordPage } from "@/api/index";

export default {
  name: "driverAnalyse",
  data() {
    return {
      loading: false,
      month: "",
      searchForm: {
        // 搜索框初始化对象
        fileName: "",
        mobile: "",
        pageNumber: 1, // 当前页数
        pageSize: 10, // 页面大小
        fileType: "",
        state: "",
        startDate: "",
        endDate: "",
      },

      form: {},
      columns: [
        {
          title: "#",
          type: "index",
          minWidth: 60,
        },
        {
          title: "文件名",
          key: "fileName",
          minWidth: 350,
          sortable: false,
          tooltip: true,
        },
        {
          title: "导出类型",
          key: "fileType",
          minWidth: 220,
          render: (h, params) => {
            let textName = "";
            if (params.row.fileType == 1) {
              textName = "用户数据";
            } else if (params.row.fileType == 2) {
              textName = "订单数据";
            } else if (params.row.fileType == 3) {
              textName = "运单数据";
            } else if (params.row.fileType == 4) {
              textName = "监控数据";
            } else if (params.row.fileType == 5) {
              textName = "发票数据";
            } else if (params.row.fileType == 6) {
              textName = "财务数据";
            } else if (params.row.fileType == 7) {
              textName = "统计数据";
            } else {
              textName = "未知类型";
            }
            return h("div", textName);
          },
        },

        {
          title: "导出日期",
          key: "createTime",
          minWidth: 250,
        },
        {
          title: "备注",
          key: "remarks",
          minWidth: 300,
          render: (h, params) => {
            if (params.row.remarks == "" || params.row.remarks == "undefined") {
              return h(
                "div",
                {
                  style: {
                    color: "#B0C4DE",
                  },
                },
                "未填写"
              );
            } else {
              return h("div", params.row.remarks);
            }
          },
        },
        {
          title: "状态",
          key: "state",
          minWidth: 130,
          render: (h, params) => {
            if (params.row.state == "1") {
              return h("div", [
                h(
                  "Tag",
                  {
                    props: {
                      color: "#468847",
                    },
                  },
                  "成功"
                ),
              ]);
            } else if (params.row.state == "2") {
              return h("div", [
                h(
                  "Tag",
                  {
                    props: {
                      color: "#dc143c",
                    },
                  },
                  "失败"
                ),
              ]);
            }
          },
        },
        {
          title: "导出人",
          key: "createBy",
          width: 130,
          render: (h, params) => {
            let placTop = "top";
            if (params.index == 0) {
              placTop = "bottom";
            } else {
              placTop = "top";
            }
            return h(
              "Tooltip",
              {
                props: {
                  maxWidth: "120",
                  placement: placTop,
                  content: params.row.createBy,
                },
              },
              [
                h(
                  "Tag",
                  {
                    style: {
                      "margin-right": "8px",
                    },
                    props: {
                      type: "border",
                    },
                  },
                  params.row.createName
                ),
              ]
            );
          },
        },
        {
          title: "操作",
          key: "action",
          width: 90,
          render: (h, params) => {
            // return h("div", [
            //   h(
            //     "a",
            //     {
            //       on: {
            //         // click: () => {
            //         //   this.SourceDetails(params.row);
            //         // },
            //       },
            //     },
            //     "--"
            //   ),
            // ]);
            return h("div", "--");
          },
        },
      ],
      data: [], // 表单数据
      date: [],
      pageNumber: 1, // 当前页数
      pageSize: 10, // 页面大小
      total: 0, // 表单数据总数
    };
  },
  methods: {
    echartss(){
       this.$router.push({
        name: "echarts",
      });
    },
    init() {
      this.getDataList();
    },
    changeMonth() {
      let date = this.month;
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      month = month < 10 ? "0" + month : month;
      let mydate = year.toString() + month.toString();
      this.searchForm.queryMonth = mydate;
    },
    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getDataList();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.getDataList();
    },
    handleSearch() {
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      this.getDataList();
    },
    handleReset() {
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      this.searchForm.fileName = "";
      this.searchForm.mobile = "";
      this.month = "";
      this.searchForm.fileType = "";
      this.searchForm.state = "";
      delete this.searchForm.queryMonth;
      this.date = [];
      this.searchForm.startDate = "";
      this.searchForm.endDate = "";
      // 重新加载数据
      this.getDataList();
    },
    getDataList() {
      this.loading = true;
      downloadRecordPage(this.searchForm).then((res) => {
        this.loading = false;
        if (res.success) {
          this.data = res.result.records;
          this.total = res.result.total;
          if (this.data.length == 0 && this.searchForm.pageNumber > 1) {
            this.searchForm.pageNumber -= 1;
            this.getDataList();
          }
        } else {
          this.$Message.error(res.message);
        }
      });
    },
    //  搜索时间
    changeDate(val) {
      //改变选择日期
      this.searchForm.startDate = val[0];
      this.searchForm.endDate = val[1];
    },
  },
  mounted() {
    this.init();
  },
};
</script>

<style lang="less">
.table table {
  // table-layout: auto;
  width: 100% !important;
}
</style>